﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Data.OleDb;

namespace QuanLiHocSinh
{
    public partial class DangNhap : Form
    {

        OleDbConnection connect_acc;
        public DangNhap()
        {
            InitializeComponent();
            
           
            //===========================================================================================

            connect_acc = new OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=CSDL.mdb");

            if (connect_acc != null)
            {
                connect_acc.Open();
            }
            //===========================================================================================

        }


        

        
        private void button2_Click(object sender, EventArgs e)
        {
           
            if (MessageBox.Show("Bạn có chắc chắn muốn thoát chương trình", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.Yes)
            {
                connect_acc.Close();
                this.Close();
            }
            
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool flag = true;
            string out_load = "select * from acc";
            OleDbCommand command = new OleDbCommand(out_load, connect_acc);

            OleDbDataReader reader;
            reader = command.ExecuteReader();

            while (reader.Read())
            {
                string tranfer = "";
                tranfer = tranfer + reader.GetString(0);
                if (tranfer == textBox1.Text)
                {
                    string tranfer_pass = "";
                    tranfer_pass = tranfer_pass + reader.GetString(1);
                    if (tranfer_pass == textBox2.Text)
                    {
                        flag = false;
                        string mtext = "Xin chào ";
                        mtext += tranfer;
                        MessageBox.Show(mtext, "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);

                        Thread  thread_open = new Thread (new ThreadStart(open_QLHS));
                        thread_open.Start();

                        this.Close();
                        
                       
                    }
                }
                
            }
            if (flag)
            {
                MessageBox.Show("Sai tên đăng nhập hoặc mật khẩu!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
            }
        }



        static void open_QLHS()
        {

            Application.Run(new Menu());
        }  

       


    }
}
